package com.yztc.xiami_app.ui.goodsdetail.presenter;

import android.util.Log;

import com.yztc.xiami_app.bean.goodsdetails.GoodsDetailsBean;
import com.yztc.xiami_app.ui.goodsdetail.model.GoodsDetailsModelImpl;
import com.yztc.xiami_app.ui.goodsdetail.model.IGoodsDetailsModel;
import com.yztc.xiami_app.ui.goodsdetail.view.IGoodsDetailsView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 周旭 on 2016/11/19.
 * "商品详情"的Presenter层的实现类
 */

public class GoodsDetailsPresenterImpl implements IGoodsDetailsPresenter{

    private IGoodsDetailsModel mGoodsDetailsModel;
    private IGoodsDetailsView mGoodsDetailsView;


    public GoodsDetailsPresenterImpl(IGoodsDetailsView mGoodsDetailsView) {
        mGoodsDetailsModel = new GoodsDetailsModelImpl();
        this.mGoodsDetailsView = mGoodsDetailsView;

    }

    //获取商品详情的数据
    @Override
    public void getGoodsDetailsBean(String productId,String baseUrl) {
       mGoodsDetailsModel.getGoodsDetailsBean(productId,baseUrl)
               .subscribeOn(Schedulers.io())
               .observeOn(AndroidSchedulers.mainThread())
               .subscribe(new Subscriber<GoodsDetailsBean>() {
                   @Override
                   public void onCompleted() {
                       Log.i("tag","------------>onCompleted");
                   }

                   @Override
                   public void onError(Throwable e) {
                       Log.i("tag","------------>onError"+e.getMessage());
                       mGoodsDetailsView.loadError();
                   }

                   @Override
                   public void onNext(GoodsDetailsBean goodsDetailsBean) {
                       Log.i("tag","------------>onNext");
                       //商品详情页面显示数据
                       mGoodsDetailsView.showGoodsDetails(goodsDetailsBean);
                   }
               });

    }
}
